package com.tjian.fafa.user.util.text;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

/**
 * 文字工具类
 *
 * @author rendongwei
 */
public class TextUtil
{

    /**
     * 根据输入流转换成字符串
     *
     * @param inputStream 文字输入流
     * @return 文字字符串(String 类型)
     */
    public static String readTextFile(InputStream inputStream)
    {
        String readedStr = "";
        BufferedReader br;
        try
        {
            br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
            String tmp;
            while ((tmp = br.readLine()) != null)
            {
                readedStr += tmp;
            }
            br.close();
            inputStream.close();
        }
        catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }

        return readedStr;
    }

}
